package com.huangsm.book.designmodel.jvm;

import java.util.Vector;

/**
 * 分配最大堆内存
 * @author huang
 * @date 2019/2/22
 */
public class MaxHeapDemo {
    public static void main(String[] args) {
        Vector v=new Vector();
        for (int i = 1; i < 10; i++) {
            //每个循环分配1MB内存
            byte[] b = new byte[1024 * 1024];
            //强引用不会被GC回收
            v.add(b);
            System.out.println(i+"M is allocated");
        }
        System.out.println("Max Memory:"+Runtime.getRuntime().maxMemory()/1024/1024+"M");
    }
}
